package com.sky.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 */
@Slf4j
@Configuration  //配置类
@EnableSwagger2 //开启Swagger2配置
public class SwaggerConfig {


    @Bean
    public Docket docket(){
        log.info(" Swagger2 开始生成接口文档... ");
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(webApiInfo())
                .host("http://localhost:8888/swagger-ui.html")
                //分组
                .groupName("sky_take_out_API")
                //通过.select()方法，去配置扫描接口
                .select()
                //通过类上的注解扫描，如.withClassAnnotation(Controller.class)只扫描有@controller注解的类中的接口
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                //任何请求都扫描
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("苍穹外卖项目-接口文档")
                .contact(new Contact("xl", "", "2438510383@qq.com"))
                .description("苍穹外卖项目接口文档")
                .version("2.0")
                .build();

    }



}
